package com.example.mylearn.arthasTest;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;

public class CustomObjectMapper extends ObjectMapper {

    public CustomObjectMapper() {
        SimpleModule module = new SimpleModule();
        module.addSerializer(new RawStringSerializer());
        registerModule(module);
    }

    static class RawStringSerializer extends StdSerializer<String> {

        protected RawStringSerializer() {
            this(null);
        }

        protected RawStringSerializer(Class<String> t) {
            super(t);
        }

        @Override
        public void serialize(String value, JsonGenerator gen, SerializerProvider provider) throws IOException {
            gen.writeRawValue(value);
        }


        @Override
        public Class<String> handledType() {
            return String.class;
        }
    }
}